package MFL.dao.impl;

import java.sql.SQLException;
import java.util.List;

import javax.sound.midi.MidiDevice.Info;

import org.apache.commons.dbutils.handlers.ScalarHandler;

import MFL.dao.commendDao;
import MFL.handler.CommendResultSetHandler;
import basedao.BaseDao;
import bean.comment;


public class commendDaoImpl extends BaseDao implements commendDao {

	

	@Override
	public List<comment> selectcommendlist(Integer pageIndex, Integer pageSize) {
		String sql="select com1.*,pro1.proname from `comment` com1 ,product pro1 where com1.proId=pro1.proId order by com1.id  limit ?,?";
		try {
			return query.query(sql, new CommendResultSetHandler(), (pageIndex-1)*pageSize,pageSize);

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public Integer getCount() {
		String sql="select count(1) from orders";
		Object query1;
		try {
			query1 = query.query(sql, new ScalarHandler());
			return Integer.parseInt(query1.toString());
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}



	@Override
	public Integer deletecommendbyid(Integer id) {

		try {
			return query.update("delete from `comment`  where id=?",id);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return -1;
	}

	@Override
	public List<comment> selectcommendbyid(Integer id, Integer pageIndex, Integer pageSize) {
		String sql="select com1.*,pro1.proname from `comment` com1 ,product pro1 where com1.proId=pro1.proId  and com1.proId=? order by com1.id limit ?,?";
		// TODO Auto-generated method stub
		try {
			return query.query(sql, new CommendResultSetHandler(), id, (pageIndex-1)*pageSize,pageSize);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

}
